/*!
 * \file frexpect_hash_key.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include <frdb_cursor.h>
#include "frexp_comm.h"

#include "apmtest_comm.h"
#include "../../../src/module/syncmodule/syncmodule_core.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    int i_ret = 0;
    u_short us_proto = 7;
    u_int ui_src_ip = 16819218;
    u_short us_src_port = 8080;
    u_int ui_dst_ip = 19216811;
    u_short us_dst_port = 21;
    char *p_key = NULL;
    unsigned int ui_key_size = 0;

    i_ret = frexpect_hash_key(us_proto, ui_src_ip, us_src_port, ui_dst_ip
            ,us_dst_port, p_key, ui_key_size);

    CU_ASSERT_EQUAL(i_ret, 0);

    return;

}

static void __case2(void)
{
    int i_ret = 0;
    u_short us_proto = 7;
    u_int ui_src_ip = 16819218;
    u_short us_src_port = 8080;
    u_int ui_dst_ip = 19216811;
    u_short us_dst_port = 21;
    char *p_key = NULL;
    unsigned int ui_key_size = 14;

    p_key = (char *)frmalloc(ui_key_size);
    memset(p_key, 0x00, ui_key_size);

    i_ret = frexpect_hash_key(us_proto, ui_src_ip, us_src_port, ui_dst_ip
            ,us_dst_port, p_key, ui_key_size);

    CU_ASSERT_EQUAL(i_ret, 0);

    frfree(p_key);
    return;

}

static void __case3(void)
{
    int i_ret = 0;
    u_short us_proto = 7;
    u_int ui_src_ip = 16819218;
    u_short us_src_port = 8080;
    u_int ui_dst_ip = 19216811;
    u_short us_dst_port = 21;
    char *p_key = NULL;
    unsigned int ui_key_size = 18;

    p_key = (char *)frmalloc(ui_key_size);
    memset(p_key, 0x00, ui_key_size);

    i_ret = frexpect_hash_key(us_proto, ui_src_ip, us_src_port, ui_dst_ip
            ,us_dst_port, p_key, ui_key_size);

    CU_ASSERT_EQUAL(i_ret, 14);

    frfree(p_key);
    return;

}


int add_suite_frexpect_hash_key(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frdb_cursor frexpect_hash_key()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);

    return FR_SUCC;
}
